<?php

class mySqlConnector{

	//declaro las properties (o atributos)
	private $_host;
	private $_user;
	private $_pass;
	private $_db;
	private $_conn;
	private $_lastInsertId;

	public function __construct($host, $user, $pass, $db){
		//seteo las properties
		$this->_host = $host;
		$this->_user = $user;
		$this->_pass = $pass;
		$this->_db = $db;
		

	}
	
	public function connect(){
		$this->_conn = new mysqli($this->_host ,$this->_user , $this->_pass, $this->_db);
		
	}
	
	public function abmQuery($query) {
		$resultado = $this->_conn->query($query);
		
		
		if (intval($this->_conn->insert_id)>0){
			//convierte a entero lo que le pase
			$this->_lastInsertId = $this->_conn->insert_id;
			
			
		}
		return true;
	}
	
	public function getLastInsertId(){
		return $this->_lastInsertId;
	}
	
	public function selectQuery($query){
		$resultado = $this->_conn->query($query);
		$filas = array();
		if($resultado){
			// Cycle through results
			while ($row = $resultado->fetch_object()){
				$filas[] = $row;
			}
			// Free result set
			$resultado->close();
			if ($this->_conn->more_results()){
				$this->_conn->next_result();
			}
		}
		return $filas;
	}
}